﻿<%@ Page Title="DSHS" Language="C#" MasterPageFile="~/main/masterpage/main_level1.Master"
    AutoEventWireup="true" CodeBehind="dsbangkhaosat.aspx.cs" Inherits="nkstdgia.main.dsbangkhaosat" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<%@ Register Assembly="wsRK.wsControls" Namespace="wsRK.wsControls" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="phd_content" runat="server">

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<%= Google_API_key%>"
        type="text/javascript"></script>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div class="webapplication_form_header">
                <div class="left">
                    <h1>
                        <asp:Label ID="lblTitle" runat="server">Tìm kiếm bảng khảo sát</asp:Label>
                    </h1>
                </div>
            </div>
            <table class="option_table">
                <tr>
                    <td style="width: 50%">
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Phiếu số</span>
                        </div>
                        <div class="left">
                            <asp:TextBox ID="txtPhieuSo" runat="server" Width="100px" MaxLength="100"></asp:TextBox>
                        </div>
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Trạng thái phiếu</span>
                        </div>
                        <div class="left">
                            <cc1:wsLstDropdownlist ID="ddlTrangThai" runat="server" AddBlankRow="true">
                                <asp:ListItem Value="-999999">------</asp:ListItem>
                                <asp:ListItem Value="0">Hoàn thành</asp:ListItem>
                                <asp:ListItem Value="1">Bản thảo</asp:ListItem>
                            </cc1:wsLstDropdownlist>
                        </div>
                    </td>
                    <td style="width: 50%">
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Tên chủ sở hữu</span>
                        </div>
                        <div class="left">
                            <asp:TextBox ID="txtChuSuDung" runat="server" Width="200px" MaxLength="200"></asp:TextBox>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Quận</span>
                        </div>
                        <div class="left">
                            <cc1:wsLstDropdownlist ID="ddlQuan" runat="server" DataTextField="NOI_DUNG" DataValueField="MA_THAM_SO"
                                AutoPostBack="True" OnSelectedIndexChanged="ddlQuan_SelectedIndexChanged" AddBlankRow="true">
                            </cc1:wsLstDropdownlist>
                        </div>
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Phường</span>
                        </div>
                        <div class="left">
                            <cc1:wsLstDropdownlist ID="ddlPhuong" runat="server" DataTextField="NOI_DUNG" DataValueField="MA_THAM_SO"
                                AddBlankRow="true">
                            </cc1:wsLstDropdownlist>
                        </div>
                    </td>
                    <td>
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Giá</span>
                        </div>
                        <div class="left">
                            <cc1:wsLstDropdownlist ID="ddlGiaDat" runat="server" AddBlankRow="true">
                                <asp:ListItem Value="-999999">------</asp:ListItem>
                                <asp:ListItem Value="0">Nhỏ hơn 1 tỉ</asp:ListItem>
                                <asp:ListItem Value="1">Từ 1 tỉ đến 2.5 tỉ</asp:ListItem>
                                <asp:ListItem Value="2">Từ 2.5 tỉ đến 5 tỉ</asp:ListItem>
                                <asp:ListItem Value="3">Lớn 5 tỉ</asp:ListItem>
                            </cc1:wsLstDropdownlist>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Đường</span>
                        </div>
                        <div class="left">
                            <asp:TextBox ID="txtDuong" runat="server" Width="300px" MaxLength="200"></asp:TextBox>
                        </div>
                    </td>
                    <td>
                        <div class="left textright option_table_td_100" style="margin-right: 10px">
                            <span>Đoạn đường</span>
                        </div>
                        <div class="left">
                            <asp:TextBox ID="txtDoanDuong" runat="server" Width="300px" MaxLength="200"></asp:TextBox>
                        </div>
                    </td>
            </table>
            <div class="action_bar">
                <div style="margin-top: 5px; float: left">
                    <span>Đơn vị tính: triệu VND</span>
                </div>
                <div class="right ">
                    <cc1:wsBtnAction ID="btnExport" runat="server" LocaleText="Report" ButtonType="ButtonExport"
                        OnClick="btnExport_Click"></cc1:wsBtnAction>
                    <cc1:wsBtnAction ID="btnAdd" runat="server" LocaleText="Add" ButtonType="ButtonAdd"
                        PostBackUrl="ctbangkhaosat.aspx"></cc1:wsBtnAction>
                    <cc1:wsBtnAction ID="btnSearch" runat="server" LocaleText="Search" ButtonType="ButtonSearch"
                        OnClick="btnSearch_Click" OnClientClick="javascript:Dialog.showLoader();"></cc1:wsBtnAction>
                </div>
            </div>
            <cc1:wsLstListView ID="lvDSKhaoSat" runat="server" OnbtnFirst_Click="_lv_btnFirst_Click"
                OnbtnLast_Click="_lv_btnLast_Click" OnbtnNext_Click="_lv_btnNext_Click" OnbtnPrev_Click="_lv_btnPrev_Click"
                OnddlPageSize_SelectedIndexChanged="_lv_ddlPageSize_SelectedIndexChanged" OnddlPageIndex_SelectedIndexChanged="_lv_ddlPageIndex_SelectedIndexChanged"
                OnItemDataBound="lvDSKhaoSat_ItemDataBound">
                <LayoutTemplate>
                    <table class="data_table">
                        <tr>
                            <th style="width: 40px">
                                #
                            </th>
                            <th style="width: 70px">
                                <asp:LinkButton ID="LinkButton5" runat="server" OnClick="sortbyPhieuso_click">Ph. số</asp:LinkButton>
                            </th>
                            <th>
                                Địa chỉ khảo sát
                            </th>
                            <th class="width100">
                                <asp:LinkButton ID="LinkButton6" runat="server" OnClientClick="javascript:Dialog.showLoader();"
                                    OnClick="sortbyGiaGiaoDich_click">Giá giao dịch</asp:LinkButton>
                            </th>
                            <th id="thG1" runat="server" class="width100">
                                <asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="javascript:Dialog.showLoader();"
                                    OnClick="sortbyGia1_click">Giá TB 1</asp:LinkButton>
                            </th>
                            <th id="thG2" runat="server" class="width100">
                                <asp:LinkButton ID="LinkButton3" runat="server" OnClientClick="javascript:Dialog.showLoader();"
                                    OnClick="sortbyGia2_click">Giá TB 2</asp:LinkButton>
                            </th>
                            <th class="width50">
                                <asp:LinkButton ID="LinkButton4" runat="server" OnClientClick="javascript:Dialog.showLoader();"
                                    OnClick="sortbyStatus_click">Tr. thái</asp:LinkButton>
                            </th>
                            <th class="width50">
                            </th>
                        </tr>
                        <tr id="itemPlaceholder" runat="server">
                        </tr>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <%# Eval("RowNumber") %>
                        </td>
                        <td>
                            <%# Eval("SO_PHIEU") %>
                        </td>
                        <td style="text-align: left">
                            <asp:Image ID="imgMajor" runat="server" ImageUrl='<%# Eval("SO_PHIEU") %>' />
                            <asp:HyperLink ID="lkPhieuKhaoSat" runat="server" Target="_blank" Text='<%# Eval("DIA_CHI") %>'
                                NavigateUrl='<%# "ctbangkhaosat.aspx?phieuID=" + Eval("MA_HO_SO") %>'></asp:HyperLink>
                            <br />
                            <asp:Label ID="gpsLatPhieuKhaoSat" runat="server" Text='<%#Eval("GPS_LATITUDE")%>' />
                            <asp:Label ID="gpsLonPhieuKhaoSat" runat="server" Text='<%#Eval("GPS_LONGTITUDE")%>'/>
                            <label>
                                <%# Eval("DUONG").ToString() + ", " + Eval("DOAN_DUONG").ToString() + ", " + Eval("TEN_PHUONG").ToString() + ", " + Eval("TEN_QUAN").ToString() %></label>
                            <asp:Panel ID="Panel1" runat="server" CssClass="tooltip" Width="350px">
                                <table style="width: 100%">
                                    <tr>
                                        <td style="width: 110px">
                                            <span style="font-weight: bold">Chủ sử dụng : </span>
                                        </td>
                                        <td style="text-align: left">
                                            <asp:Label ID="TitleLabel" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt"
                                                ForeColor="#006600" Text='<%# Eval("TEN_CHU_SU_DUNG") %>'></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left">
                                            <span style="font-weight: bold">Ngày khảo sát : </span>
                                        </td>
                                        <td>
                                            <%# DateTime.Parse(Eval("NGAY_KHOI_TAO").ToString()).ToShortDateString() %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left">
                                            <span style="font-weight: bold">Người cập nhật : </span>
                                        </td>
                                        <td>
                                            <%# Eval("UserName") %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left">
                                            <span style="font-weight: bold">Ngày cập nhật : </span>
                                        </td>
                                        <td>
                                            <%# Eval("NGAY_CAP_NHAT") %>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                            <cc2:HoverMenuExtender ID="HoverMenuExtender1" runat="server" PopupControlID="Panel1"
                                TargetControlID="lkPhieuKhaoSat" PopupPosition="right" OffsetX="0" OffsetY="0">
                            </cc2:HoverMenuExtender>
                        </td>
                        <td style="text-align: right">
                            <%# Eval("GIA_GIAO_DICH_TRIEU_DONG").ToString() == "0" ? "" : string.Format("{0:###,###,##0.000}", double.Parse(Eval("GIA_GIAO_DICH_TRIEU_DONG").ToString()))%>
                        </td>
                        <td id="td1GD1" runat="server" style="text-align: right">
                            <%# double.Parse(Eval("GIA_DAT_BINH_QUAN_1").ToString()) <= 0 ? "N/A": string.Format("{0:###,###,##0.000}", double.Parse(Eval("GIA_DAT_BINH_QUAN_1").ToString())) %>
                        </td>
                        <td id="td1GD2" runat="server" style="text-align: right">
                            <%# double.Parse(Eval("GIA_DAT_BINH_QUAN_2").ToString()) <= 0 ? "N/A": string.Format("{0:###,###,##0.000}", double.Parse(Eval("GIA_DAT_BINH_QUAN_2").ToString())) %>
                        </td>
                        <td>
                            <asp:Image ID="imgStatus" runat="server" ImageUrl='<%# Eval("ACTIVE_FLAG").ToString()=="Y"?"~/images/ready.png":"~/images/notyet.png" %>'
                                AlternateText='<%# Eval("ACTIVE_FLAG").ToString()=="Y"?"Hoàn thành":"Chưa xong" %>' />
                        </td>
                        <td>
                            <asp:HyperLink ID="lbtnExport" runat="server" ImageUrl="~/images/iconExcel.gif" Width="16px"
                                Height="16px" NavigateUrl='<%# "~/FileDownload.ashx?type=exportptd&id=" + Eval("MA_HO_SO").ToString() %>'
                                Visible='<%# Eval("ACTIVE_FLAG").ToString()=="Y"?true:false %>'></asp:HyperLink>
                        </td>
                    </tr>
                </ItemTemplate>
                <AlternatingItemTemplate>
                    <tr class="altrow">
                        <td>
                            <%# Eval("RowNumber") %>
                        </td>
                        <td>
                            <%# Eval("SO_PHIEU") %>
                        </td>
                        <td style="text-align: left">
                            <asp:Image ID="imgMajor" runat="server" ImageUrl='<%# Eval("SO_PHIEU") %>' />
                            <asp:HyperLink ID="lkPhieuKhaoSat" runat="server" Target="_blank" Text='<%# Eval("DIA_CHI") %>'
                                NavigateUrl='<%# "ctbangkhaosat.aspx?phieuID=" + Eval("MA_HO_SO") %>'></asp:HyperLink>
                            <br />
                            <label>
                                <%# Eval("DUONG").ToString() + ", " + Eval("DOAN_DUONG").ToString() + ", " + Eval("TEN_PHUONG").ToString() + ", " + Eval("TEN_QUAN").ToString() %></label>
                            <asp:Panel ID="Panel1" runat="server" CssClass="tooltip" Width="350px">
                                <table style="width: 100%">
                                    <tr>
                                        <td style="width: 110px">
                                            <span style="font-weight: bold">Chủ sử dụng : </span>
                                        </td>
                                        <td style="text-align: left">
                                            <asp:Label ID="TitleLabel" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt"
                                                ForeColor="#006600" Text='<%# Eval("TEN_CHU_SU_DUNG") %>'></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left">
                                            <span style="font-weight: bold">Ngày khảo sát : </span>
                                        </td>
                                        <td>
                                            <%# DateTime.Parse(Eval("NGAY_KHOI_TAO").ToString()).ToShortDateString() %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left">
                                            <span style="font-weight: bold">Người cập nhật : </span>
                                        </td>
                                        <td>
                                            <%# Eval("UserName") %>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: left">
                                            <span style="font-weight: bold">Ngày cập nhật : </span>
                                        </td>
                                        <td>
                                            <%# Eval("NGAY_CAP_NHAT") %>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>
                            <cc2:HoverMenuExtender ID="HoverMenuExtender1" runat="server" PopupControlID="Panel1"
                                TargetControlID="lkPhieuKhaoSat" PopupPosition="right" OffsetX="0" OffsetY="0">
                            </cc2:HoverMenuExtender>
                        </td>
                        <td style="text-align: right">
                            <%# Eval("GIA_GIAO_DICH_TRIEU_DONG").ToString() == "0" ? "" : string.Format("{0:###,###,##0.000}", double.Parse(Eval("GIA_GIAO_DICH_TRIEU_DONG").ToString()))%>
                        </td>
                        <td id="td2GD1" runat="server" style="text-align: right">
                            <%# double.Parse(Eval("GIA_DAT_BINH_QUAN_1").ToString()) <= 0 ? "N/A": string.Format("{0:###,###,##0.000}", double.Parse(Eval("GIA_DAT_BINH_QUAN_1").ToString())) %>
                        </td>
                        <td id="td2GD2" runat="server" style="text-align: right">
                            <%# double.Parse(Eval("GIA_DAT_BINH_QUAN_2").ToString()) <= 0 ? "N/A": string.Format("{0:###,###,##0.000}", double.Parse(Eval("GIA_DAT_BINH_QUAN_2").ToString())) %>
                        </td>
                        <td>
                            <asp:Image ID="imgStatus" runat="server" ImageUrl='<%# Eval("ACTIVE_FLAG").ToString()=="Y"?"~/images/ready.png":"~/images/notyet.png" %>'
                                AlternateText='<%# Eval("ACTIVE_FLAG").ToString()=="Y"?"Hoàn thành":"Chưa xong" %>' />
                        </td>
                        <td>
                            <asp:HyperLink ID="lbtnExport" runat="server" ImageUrl="~/images/iconExcel.gif" Width="16px"
                                Height="16px" NavigateUrl='<%# "~/FileDownload.ashx?type=exportptd&id=" + Eval("MA_HO_SO").ToString() %>'
                                Visible='<%# Eval("ACTIVE_FLAG").ToString()=="Y"?true:false %>'></asp:HyperLink>
                        </td>
                    </tr>
                </AlternatingItemTemplate>
                <EmptyDataTemplate>
                    <table class="data_table">
                        <tr>
                            <th style="width: 40px">
                                #
                            </th>
                            <th style="width: 70px">
                                Ph. số
                            </th>
                            <th>
                                Địa chỉ khảo sát
                            </th>
                            <th class="width100">
                                Giá giao dịch
                            </th>
                            <th id="td3GD1" runat="server" class="width100">
                                Giá TB 1
                            </th>
                            <th id="td3GD2" runat="server" class="width100">
                                Giá TB 2
                            </th>
                            <th class="width50">
                                Tr. thái
                            </th>
                            <th class="width50">
                            </th>
                        </tr>
                        <tr>
                            <td colspan="9">
                                <label runat="server">
                                    <%= base.getValueFromLocale("NoData")%></label>
                            </td>
                        </tr>
                    </table>
                </EmptyDataTemplate>
            </cc1:wsLstListView>
            <br>
            <% 
                if (this.lvDSKhaoSat.Items.Count > 0)
                { 
            %>
            <div class="box-br" id="g_map">
                <div class="box-bl">
                    <div class="box-tr">
                        <div class="box-tl">
                            <div id="map_canvas" style="width: 1200px; height: 700px; padding: 15px;">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <% 
                } 
            %>
            <br />
        </ContentTemplate>
    </asp:UpdatePanel>

    <script type="text/javascript">
        var map;
        var geocoder;
        var default_point = new GLatLng(10.7986288, 106.6876067);
        var default_zoom = 17;

        function initialize_map() {
            map = new GMap2(document.getElementById("map_canvas"));
            map.setUIToDefault();
            map.disableScrollWheelZoom();
            geocoder = new GClientGeocoder();
            getAllAddressMarket();
        }
        function getAllAddressMarket() {
            var arrAddress = $("a[id*='lkPhieuKhaoSat']").toArray();
            var arrLink = $("a[id*='lkPhieuKhaoSat']").toArray();
            var arrCost1 = $("td[id*='GD1']").toArray();
            var arrCost2 = $("td[id*='GD2']").toArray();
            var arrgpsLat = $("span[id*='gpsLatPhieuKhaoSat']").toArray();
            var arrgpsLon = $("span[id*='gpsLonPhieuKhaoSat']").toArray();
                        
            
            //alert(arrAddress.length + "_" + arrLink.length + "_" + arrCost1.length + "_" + arrCost2.length + "_")
            for (var i = 0; i < arrAddress.length; i++) {
                arrgpsLat[i].style.display = "none";
                arrgpsLon[i].style.display = "none";
                
                if (arrCost1.length > 0 && arrCost2.length > 0)
                    get_latlong(arrAddress[i].innerHTML, arrLink[i].href, arrCost1[i].innerHTML, arrCost2[i].innerHTML, arrgpsLat[i], arrgpsLon[i]);
                else
                    get_latlong(arrAddress[i].innerHTML, arrLink[i].href, '', '', arrgpsLat[i], arrgpsLon[i]);
            }
            if (arrAddress.length <= 0)
                document.getElementById("g_map").style.display = 'none';
        }
        function get_latlong(address, link, cost1, cost2, lat, lon) {
            var msg = "";
            msg += '<b>Địa chỉ&nbsp;&nbsp;:&nbsp;</b>' + address + '<br>';
            msg += '<b>Liên kết&nbsp;:&nbsp;</b>' + '<a href="' + link + '">Xem ở trang chi tiết</a><br>';
            if (cost1 && cost2) {
                msg += '<b>Giá đất 1:&nbsp;</b>' + cost1 + '<br>';
                msg += '<b>Giá đất 2:&nbsp;</b>' + cost2 + '<br>';
            }
            
            if (geocoder) {
                geocoder.getLatLng(
                  address,
                  function(point) {
                      if (!point) {
                          //alert(address + " not found" + lon.innerHTML + lat.innerHTML);
                          var marker = new GMarker(new GPoint(lon.innerHTML, lat.innerHTML));
                          GEvent.addListener(marker, "click", function() {
                              marker.openInfoWindowHtml(msg);
                          });
                          map.addOverlay(marker);
                          map.setCenter(new GPoint(lon.innerHTML, lat.innerHTML), default_zoom);
                      } else {
                          var marker = new GMarker(point);
                          GEvent.addListener(marker, "click", function() {
                              marker.openInfoWindowHtml(msg);
                          });
                          map.addOverlay(marker);
                          map.setCenter(point, default_zoom);
                      }
                  }
                );
            }
        }
        function pageLoad(sender, args) {
            try {
                if (args.get_isPartialLoad() && document.getElementById("map_canvas")) {
                    initialize_map();
                }
            }
            catch (err) {
                //alert('gmap loading error!!!' + err)
            }
        }
           
    </script>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="phd_footer" runat="server">
</asp:Content>
